<?php
/**
 * Punny - The most easy-to-use PHP MVC framework
 * 
 * Copyright (c) 2010  
 *
 * @author email :lx.xin@qq.com
 */
 require('BaseController.php');
 class TagController extends BaseController{	
	function init(){
		parent::init();		
		$this->view->tags=$this->side_tag();
	}

	function indexAction(){
	
		
		echo $this->view->render('tags.html');
	}
	/*
	 *通过ID，查询日志
	 */

	 function singleAction(){
		$id=$this->_request->get('id');		
		$blog=new Blog();
		$blog->updateHit($id);
		$data=$blog->queryBlog($id);
		//Zend_debug::dump($data);
		$this->view->id=$data['id'];
		$this->view->title=$data['title'];
		$this->view->content=$data['content'];
		$this->view->posttime=$data['posttime'];
		$this->view->commnums=$data['commnums'];
		$this->view->viewnums=$data['viewnums'];
		$this->view->author=$data['author'];		
		$this->view->iscomment==$data['iscomment'];		
		//加载评论
		$comm=new Comment();
		$arrComm=$comm->queryComment($id);
		$comment=array();
		foreach($arrComm as $key=>$val){
			$comment[$key]['id'] =$val['id'];
			$comment[$key]['name']=$val['name'];
			$comment[$key]['content']=$val['content'];
			$comment[$key]['posttime']=$val['posttime'];
		}
		$this->view->comment=$comment;		
		//Zend_debug::dump($data);
		$this->view->x='single';
		echo $this->view->render('tags.html');
	 }

	 /*
	  *通过类型，查询某一类日志
	  */
	  function doubleAction(){
		$numPerPage = 5;
		$getPage = $this->_request->getParam('page');
		$page = empty($getPage)?'1':$getPage;
		
		$name=$this->_request->get('name');
		$blog=new Blog();
		$blogarr=$blog->tagToBlog($name);
		if(empty($blogarr)){
			echo "<script language='javascript'>alert('该分类下，暂无日志！');history.go(-1);</script>";
			exit;
		}
		/*$blog_arr=array();
		foreach($blogarr as $key=>$value){
			$blog_arr[$key]['id'] = $value['id'];			
			$blog_arr[$key]['title'] = $value['title'];		
			$blog_arr[$key]['content']  = $value['content'];
			$blog_arr[$key]['posttime'] = $value['posttime'];
			$blog_arr[$key]['commnums'] = $value['commnums'];
			$blog_arr[$key]['author'] = $value['author'];
			$blog_arr[$key]['viewnums'] = $value['viewnums'];
		}*/

		//Zend_debug::dump($q);
		//factory出一个分页并且设置当前页码与每页显数
		$paginator = Zend_Paginator::factory($blogarr);
		$paginator->setCurrentPageNumber($page)
				  ->setItemCountPerPage($numPerPage);
         //把分页显示到view
		$this->view->paginator = $paginator;			

		$this->view->blogarr=$blogarr;
		$this->view->x='double';
		echo $this->view->render('tags.html');
	  }
	  /*
	   *提交评论
	   */
	   function commentAction (){
			$filter=array(
				'*'=>'StringTrim'					
			);
			$validate=array(
					'name'=>array(
						array('StringLength',1,100),
						Zend_Filter_Input::MESSAGES=>array(array(
							Zend_Validate_StringLength::INVALID=>"请输入一个合法的字符串",
							Zend_Validate_StringLength::TOO_SHORT=>"请输入字符长度为1-100",
							Zend_Validate_StringLength::TOO_LONG=>"请输入字符长度为1-100"	
					))
					),
					'email'=>array('NotEmpty','message'=>array(
						Zend_Validate_NotEmpty::IS_EMPTY=>"不能为空"
					)),
					'content'=>array('NotEmpty','message'=>array(
						Zend_Validate_NotEmpty::IS_EMPTY=>"不能为空"
					))
				);
			$input= new Zend_Filter_Input($filter,$validate,$this->getRequest()->getPost());
			if($input->isValid()){
				require('./library/Custom/function.inc.php');
				$comm= new Comment();
				$blog= new Blog();
				$data=$input->getEscaped();
				$data['blogid']=$_POST['blogid'];
				$data['ip']=getip();
				$data['posttime']=time();
				//Zend_debug::dump($data);
				$comm->addComment($data);
				$blog->updateComm($data['blogid']);
				echo "<script language='javascript'>alert('评论成功');window.history.back(-1);</script>";
			}
			else{
				echo "<script language='javascript'>alert('提交数据不符合，请检查！');history.go(-1);</script>";
				exit;
			}

	   }

 }






 ?>